<!--
* description: 客户管理
* author: laimzh
* createdDate: 2019-08-14
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamicButtons="tableButtons"
      :dynamicComponents="tableComponents"
      :dynamicSearchField="placeHolder"
      :dynamicApiConfig="apiConfig"
      :dynamicTableCols="tableCols"
      :dynamicFormFields="formField"
      :dynamicIsShowSelect="false"
      :dynamicIsShowMoreBtn="true"
      :dynamicButtonsRight="tableButtonsRight"
      :dynamicToggleParam="true"
    />
    <edit
      :dynamicEditRowData="editRowData"
      :popupsVisible="editPopupsVisible"
      :key="editPopupsKey"
      :popupsState="editPopupsState"
    ></edit>
  </div>
</template>
<script>
import { oneTableTemplateMixins } from "@/components/mixins/oneTableTemplateMixins";
import { crmApis } from "@/api/apiList/crm";
import { requestAPI } from "@/api/commonRequest";
export default {
  name: "CustInfo",
  // 组件混入对象
  mixins: [oneTableTemplateMixins],
  components: {
    OneTableTemplate: () => import("@/components/crm/Template/crmonePage"),
    edit: () => import("./getOemCustInfo")
  },
  data() {
    return {
      editPopupsKey: "",
      editPopupsState: "",
      editPopupsVisible: false,
      editRowData: {},
      queryParam: "",
      // placeHolder: `客户名称/电话`,
      currentRow: null,
      newTable: [],
      apiConfig: crmApis.mdmDlrCustInfoQueryGetCustList, //专营店客户信息查询api
      // 动态组件-按钮
      tableButtonsRight: [
        {
          compKey: "btnKey10001",
          type: "",
          size: "small",
          icon: "iconfont icon-reset",
          clickEvent: () => this.reset(),
          text: "重置"
        },
        {
          compKey: "btnKey10000",
          type: "primary",
          icon: "iconfont icon-search",
          size: "small",
          clickEvent: () => this.query(1),
          text: "查询"
        }
      ],
      tableButtons: [
        {
          compKey: "btnKey3",
          class: "el-button--primary-crm",
          size: "small",
          clickEvent: () => this.addPer(),
          text: "新增个人客户",
          isShow: this.$store.getters.orgInfo.ORG_TYPE == "0" ? true : false
        },
        {
          compKey: "btnKey4",
          class: "el-button--primary-crm",
          size: "small",
          clickEvent: () => this.addCom(),
          text: "新增公司客户",
          isShow: this.$store.getters.orgInfo.ORG_TYPE == "0" ? true : false
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "compKey1",
          labelName: "客户名称",
          codeField: "custName",
          component: () => import("@/components/org/commonInput"),
          type: "inputText",
          isMust: false
          //  popups: {type: 'propus', key: 'key1', state: false, component: () => import('@/components/org/orgDlr/orgDlr')}
        },
        {
          compKey: "compKey2",
          labelName: "电话",
          codeField: "phone",
          component: () => import("@/components/org/commonInput"),
          type: "inputText",
          isMust: false
        },
        {
          compKey: "compKey3",
          labelName: "车牌号",
          codeField: "carLicenseNo",
          component: () => import("@/components/org/commonInput"),
          type: "inputText",
          isMust: false
        },
        {
          compKey: "compKey4",
          labelName: "VIN码",
          codeField: "vin",
          component: () => import("@/components/org/commonInput"),
          type: "inputText",
          isMust: false
        },

        {
          compKey: "compKey5",
          labelName: "UID",
          codeField: "uid",
          component: () => import("@/components/org/commonInput"),
          type: "inputText",
          isMust: false
        },
        {
          compKey: "compKey6",
          labelName: "客户类型",
          lookuptype: "DB0006",
          codeField: "custClassCode",
          component: () => import("@/components/org/LookupValue"),
          type: "dropdownList",
          isMust: false
        },
        {
          compKey: "compKey7",
          labelName: "类型",
          lookuptype: "LX851",
          codeField: "custType",
          component: () => import("@/components/org/LookupValue"),
          type: "dropdownList",
          isMust: false
        },
        // {
        //   compKey: "compKey8",
        //   labelName: "是否会员",
        //   codeField: "isMember",
        //   lookuptype: "DB0064",
        //   component: () => import("@/components/org/LookupValue"),
        //   type: "dropdownList",
        //   isMust: false
        // },
        // {
        //   compKey: "compKey9",
        //   labelName: "忠诚度级别",
        //   codeField: "classLevel",
        //   lookuptype: "LX830",
        //   component: () => import("@/components/org/LookupValue"),
        //   type: "dropdownList",
        //   isMust: false
        // }
      ],
      // 动态生成网格列
      tableCols: [
        {
          prop: "controlBtn",
          label: "操作",
          codeField: "controlBtn",
          width: 210,
          align: "center",
          isComponent: true,
          fixed: true,
          comps:
            this.$store.getters.orgInfo.ORG_TYPE == "0"
              ? [
                  {
                    compKey: "propKey2",
                    labelName: "详情",
                    codeField: "editControlBtn",
                    clickEvent: index => this.detail(index),
                    component: () => import("@/components/org/linkButton"),
                    align: "center"
                  }
                ]
              : [
                  {
                    compKey: "propKey1",
                    labelName: "修改",
                    codeField: "editControlBtn",
                    clickEvent: index => {
                      this.edit(index);
                    },
                    component: () => import("@/components/org/linkButton"),
                    align: "center"
                  },
                  {
                    compKey: "propKey3",
                    labelName: "详情",
                    codeField: "editControlBtn",
                    clickEvent: index => this.detail(index),
                    component: () => import("@/components/org/linkButton"),
                    align: "center"
                  },
                  {
                    compKey: "propKey4",
                    labelName: "非本品牌车辆维护",
                    codeField: "editControlBtn",
                    clickEvent: index => this.carEdit(index),
                    component: () => import("@/components/org/linkButton"),
                    align: "center"
                  }
                ]
        },
        { prop: "custName", label: "客户名称", width: 150, align: "center" },
        { prop: "phone", label: "电话", width: 120, align: "center" },
        { prop: "genderName", label: "性别", width: 70, align: "center" },
        { prop: "carLicenseNo", label: "车牌号", width: 120, align: "center" },
        { prop: "vin", label: "VIN码", width: null, align: "center" },
        { prop: "uid", label: "UID", width: null, align: "center" },
        {
          prop: "custClassName",
          label: "客户类型",
          width: 120,
          align: "center"
        },
        { prop: "custType", label: "类型", width: 120, align: "center" },
        // {
        //   prop: "classLevel",
        //   label: "忠诚度级别",
        //   width: null,
        //   align: "center"
        // },

        // {
        //   prop: "isMemberName",
        //   label: "是否会员",
        //   width: null,
        //   align: "center"
        // },
        {
          prop: "custClassCode",
          label: "客户类型编码",
          width: null,
          align: "center",
          hidden: true
        },
        {
          prop: "dlrCustNo",
          label: "专营店客户编码",
          width: null,
          align: "center",
          hidden: true
        },
        {
          prop: "custNo",
          label: "客户编码",
          width: null,
          align: "center",
          hidden: true
        },
        {
          prop: "custFullName",
          label: "客户全称",
          width: null,
          align: "center",
          hidden: true
        },
        {
          prop: "isCarowner",
          label: "是否保客",
          width: null,
          align: "center",
          hidden: true
        }
        // { prop: "isMember", label: "是否会员", width: null, align: "center",hidden:true },
      ],
      //是否显示table下面的组件
      isShowComponent: false,
      //表单查询数据
      formField: {
        custName: "",
        phone: "",
        carLicenseNo: "",
        vin: "",
        uid: "",
        custClassCode: "0",
        // isMember: "",
        classLevel: "",
        isCurBrand: "1",
        custType: ""
      }
    };
  },
  mounted() {},
  methods: {
    //修改客户信息
    edit(currentRow) {
      let that = this;
      let selectData = this.$refs.multipleTable.list[currentRow];
      selectData.status = "edit";
      selectData.hZZ = that;
      if (selectData.custClassCode == "0") {
        that.$crmcf.jumpDetailTag(
          that,
          "crmeditPer",
          "crm/editPer",
          selectData
        );
      }
      if (selectData.custClassCode == "1") {
        that.$crmcf.jumpDetailTag(
          that,
          "crmeditCom",
          "crm/editCom",
          selectData
        );
      }
    },
    // 详情
    detail(currentRow) {
      let that = this;
      let selectData = this.$refs.multipleTable.list[currentRow];
      console.log(selectData,'selectDataselectDataselectData');

      if (selectData.custClassCode == "0") {
        that.$crmcf.jumpDetailTag(that, "PerInfo", "/PerInfo", selectData);
      }
      if (selectData.custClassCode == "1") {
        that.$crmcf.jumpDetailTag(that, "ComInfo", "/ComInfo", selectData);
      }
    },
    // 非本品牌车辆维护
    carEdit(currentRow) {
      let that = this;
      let selectData = this.$refs.multipleTable.list[currentRow];
      selectData.hZZ = that;
      that.$crmcf.jumpDetailTag(
        that,
        "crmNonThisBrandCar",
        "crm/NonThisBrandCar",
        selectData
      );
    },
    //查看客户视图
    // viewCust() {},
    // 弹窗出现方法
    addPer() {
      let selectData = {};
      let that = this;
      selectData.status = "add";
      selectData.hZZ = that;
      that.$crmcf.jumpDetailTag(that, "crmeditPer", "crm/editPer", selectData);
    },
    addCom() {
      let selectData = {};
      let that = this;
      selectData.status = "add";
      that.$crmcf.jumpDetailTag(that, "crmeditCom", "crm/editCom", selectData);
    },
    showaddPer(type) {
      this.editPerPopupsState = type;
      this.editPerPopupsVisible = true;
      this.editPerPopupsKey = this.$utils.generateId();
    },
    handeditPerVisibleFunc(val) {
      this.editPerPopupsVisible = false;
    },
    // 关闭个人维护弹窗
    editPerclose(type) {
      this.editPerPopupsVisible = false;
      this.editPerPopupsKey = this.$utils.generateId();
    },
    // 弹窗出现方法
    showaddCom(type) {
      this.editComPopupsState = type;
      this.editComPopupsVisible = true;
      this.editComPopupsKey = this.$utils.generateId();
    },
    handeditComVisibleFunc(val) {
      this.editComPopupsVisible = false;
    },
    // 关闭公司维护弹窗
    editComclose(type) {
      this.editComPopupsVisible = false;
      this.editComPopupsKey = this.$utils.generateId();
    },
    query() {
      let that = this;
      this.$refs.multipleTable.queryTable(1, null, null, {}, function(
        response
      ) {
        debugger
        if (
          (response.data.mdmDlrCustInfoQueryGetCustList.rows.length==0) &&
          this.$store.getters.orgInfo.ORG_TYPE == "1" &&
          that.formField.vin.length == 17
        ) {
          that.getCustInfo();
        }
      });
    },
    execCallBack() {
      if (arguments && arguments.length > 0) {
        const funcName = arguments[0];
        if (typeof this.callbackObj[funcName] === "function") {
          const args = [];
          if (arguments.length > 1) {
            for (let i = 1; i < arguments.length; i++) {
              args.push(arguments[i]);
            }
          }
          this.callbackObj[funcName](...args);
          return true;
        }
      }
      return false;
    },
    getCustInfo() {
      this.editRowData.vin = this.formField.vin;
      this.showEdit("edit");
    },
    // 显示新增、修改弹窗
    showEdit(type) {
      this.editPopupsState = type;
      this.editPopupsVisible = true;
      if (this.resetDialogKey === true) {
        this.editPopupsKey = this.$utils.generateId();
      }
    }
  }
};
</script>
